  import Schema from 'async-validator';
  const showMsg = (msg) => {
  wx.showToast({
    title: msg,
    icon: 'none',
    duration: 2000
  })
}
module.exports = {
  validate (key, rules, value, cb = () => {}) {
    const descriptor = {}
    descriptor[key] = rules
    const model = {}
    model[key] = value
    const validator = new Schema(descriptor);
    validator.validate(model, (errors, invalidFields) => {
      cb(!errors)
      errors && showMsg(errors[0].message)
    })
  },
  validateAll (rules, obj, cb = () => {}) {
    const validator = new Schema(rules);
    validator.validate(obj, (errors, invalidFields) => {
      cb(!errors)
      errors && showMsg(errors[0].message)
    })
  }
}